function product_buyer_get(page) {
    var url = base_url + "/product/buyer/get";
    var return_info;
    $.ajax({
        type: "get",    //请求方式
        async: false,    //是否异步
        url: url,
        data: {
            "page": page
        },    //请求参数  token
        success: function (data) {
            if (data.code === 0) {
                return_info = data.data;
            } else {
                alert_to_user(data.msg);
            }
        },
        error: function () {
            alert_to_user("请求网页失败");
        }
    })
    return return_info;
}

function product_buyer_search(word, page) {
    var url = base_url + "/product/buyer/search";
    var return_info;
    $.ajax({
        type: "get",    //请求方式
        async: false,    //是否异步
        url: url,
        data: {
            "word": word,
            "page": page
        },    //请求参数  token
        success: function (data) {
            if (data.code === 0) {
                return_info = data.data;
            } else {
                alert_to_user(data.msg);
            }
        },
        error: function () {
            alert_to_user("请求网页失败");
        }
    })
    return return_info;
}

function product_buyer_detail(productId) {
    var url = base_url + "/product/buyer/detail";
    var return_info;
    $.ajax({
        type: "get",    //请求方式
        async: false,    //是否异步
        url: url,
        data: {
            "productId": productId
        },    //请求参数  token
        success: function (data) {
            if (data.code === 0) {
                return_info = data.data;
            } else {
                alert_to_user(data.msg);
            }
        },
        error: function () {
            alert_to_user("请求网页失败");
        }
    })
    return return_info;
}

function user_buyer_info() {
    var url = base_url + "/user/buyer/info";
    var return_info;
    $.ajax({
        type: "post",    //请求方式
        async: false,    //是否异步
        url: url,
        data: {
            "token": localStorage.getItem("token")
        },    //请求参数  token
        success: function (data) {
            if (data.code === 0) {
                return_info = data.data;
            } else {
                alert_to_user(data.msg);
            }
        },
        error: function () {
            alert_to_user("请求网页失败");
        }
    })
    return return_info;
}

function product_buyer_cart_add(productId) {
    $.confirm({
        title: '加入购物车',
        content:
            '<form action="" class="formName">' +
            '<div class="form-group">' +
            '<label>请输入添加购物车商品数量(无输入默认为1)</label>' +
            '<input type="text" placeholder="商品数量(默认为1)" class="name form-control" required />' +
            '</div>' +
            '</form>',
        buttons: {
            formSubmit: {
                text: '提交',
                btnClass: 'btn-blue',
                action: function () {
                    var number = this.$content.find('.name').val();
                    if (!number) {
                        number = 1;
                    } else {
                        number = parseInt(number);
                    }
                    //添加购物车
                    var url = base_url + "/product/buyer/cart/add";
                    $.ajax({
                        type: "post",    //请求方式
                        async: false,    //是否异步
                        url: url,
                        data: {
                            "token": localStorage.getItem("token"),
                            "productId": productId,
                            "number": number
                        },    //请求参数  token
                        success: function (data) {
                            alert_to_user(data.msg);
                        },
                        error: function () {
                            alert_to_user("请求网页失败");
                        }
                    })
                }
            },
            cancel: {
                text: '取消',
                action: function () {
                    alert_to_user("没有进行操作")
                }
            },
        }
    });

}

function product_buyer_cart_list(page) {
    var url = base_url + "/product/buyer/cart/list";
    var return_info;
    $.ajax({
        type: "post",    //请求方式
        async: false,    //是否异步
        url: url,
        data: {
            "token":localStorage.getItem("token"),
            "page": page
        },    //请求参数  token
        success: function (data) {
            if (data.code === 0) {
                return_info = data.data;
            } else {
                alert_to_user(data.msg);
            }
        },
        error: function () {
            alert_to_user("请求网页失败");
        }
    })
    return return_info;
}
